package com.uuj.project.activitys;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.uuj.project.R;
import com.uuj.project.base.BaseActivity;
import com.uuj.project.base.BaseResponse;
import com.uuj.project.listener.IToolBarCallBackListener;
import com.uuj.project.presenter.MainPresenter;
import com.uuj.project.uiview.UIToolBar;
import com.uuj.project.utils.RxBusUtil;
import com.uuj.project.view.IBaseView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;

public class MainActivity extends BaseActivity<MainPresenter> implements IBaseView, IToolBarCallBackListener {


    @BindView(R.id.main)
    LinearLayout main;
    @BindView(R.id.main_toolbar)
    UIToolBar mainToolbar;
    @BindView(R.id.main_text)
    TextView mainText;
    @BindView(R.id.main_to)
    TextView mainTo;

    @Override
    protected int setContentView() {
        return R.layout.activity_main;
    }

    @Override
    protected void initData() {
        //mAgentWeb = AgentWeb.with(this)
        //        .setAgentWebParent(main, new LinearLayout.LayoutParams(-1, -1))
        //        .useDefaultIndicator()
        //        .createAgentWeb()
        //        .ready()
        //        .go("https://www.jd.com/");

        Disposable disposable = RxBusUtil.getInstance().doSubscribe(BaseResponse.class, baseResponse -> {
            mainText.setText(baseResponse.getMsg());
        }, throwable -> {
            ToastUtils.showShort(throwable.getMessage());
        });
        RxBusUtil.getInstance().addSubscription(BaseResponse.class, disposable);
    }

    @Override
    protected void initToolbar(Bundle savedInstanceState) {
        mainToolbar.setToolBarClickListener(this);
    }

    @Override
    protected MainPresenter createPresenter() {
        return new MainPresenter(this);
    }


    @Override
    public void onLeftClick() {

    }

    @Override
    public void onRightClick() {

    }

    @OnClick({R.id.main_text, R.id.main_to})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.main_text:
                presenter.getMsg();
                break;
            case R.id.main_to:
                presenter.getMsg1();
                //ActivityUtils.startActivity(RxBusActivity.class);
                break;
        }
    }
}
